<?php

class ApiObject {

    public function to_array() {
        $arr = get_object_vars($this);
        foreach ($arr as $k => $v) {
            if ($v instanceof ApiObject) {
                $arr[$k] = $v->to_array();
            } elseif (is_array($v)) {
                foreach ($v as $k1 => $v1) {
                    if ($v1 instanceof ApiObject) {
                        $v[$k1] = $v1->to_array();
                    }
                }
                $arr[$k] = $v;
            }
        }
        return $arr;
    }

}

?>
